package com.utils;

import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.poi.ss.formula.functions.T;

import java.io.Serializable;

@Data
@NoArgsConstructor
public class BaseResult<E> implements Serializable {
    private String code;

    private String msg;

    private E data;

    public enum BaseCode{
        SUCCESS("0","SUCCESS"),
        FAIL("-1","FAIL");

        private String code;
        private String message;

        BaseCode(String code,String message){
            this.code = code;
            this.message = message;
        }

        public String getCode() {
            return code;
        }

        public String getMessage() {
            return message;
        }
    }

    public BaseResult(String code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public BaseResult(String code, String msg, E data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }
    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public E getData() {
        return data;
    }

    public void setData(E data) {
        this.data = data;
    }

    public static <T> BaseResult<T> success(){
        return new BaseResult<>(BaseCode.SUCCESS.code,BaseCode.SUCCESS.message);
    }

    public static <T> BaseResult<T> success(String message) {
        return new BaseResult(BaseCode.SUCCESS.code, message);
    }

    public static <T> BaseResult<T> success(T data) {
        return new BaseResult(BaseCode.SUCCESS.code, BaseCode.SUCCESS.message, data);
    }

    public static <T> BaseResult<T> success(String message, T data) {
        return new BaseResult(BaseCode.SUCCESS.code, message, data);
    }

    public static <T> BaseResult<T> fail() {
        return new BaseResult(BaseCode.FAIL.code, BaseCode.FAIL.message);
    }

    public static <T> BaseResult<T> fail(String code) {
        return new BaseResult(code, BaseCode.FAIL.message);
    }

//    public static <T> BaseResult<T> fail(String message) {
//        return new BaseResult(BaseCode.FAIL.code, message);
//    }

    public static <T> BaseResult<T> fail(String code, String message) {
        return new BaseResult(code, message);
    }

    public static <T> BaseResult<T> fail(String message, T data) {
        return new BaseResult(BaseCode.FAIL.code, message, data);
    }

}
